package com.supermap.dataservice.temp;

import com.alibaba.dubbo.config.annotation.Service;
import com.supermap.dataservice.temp.dao.TempExpertNMDao;
import com.supermap.dataservice.temp.dao.TempUserNMDao;
import com.supermap.dataservice.util.JSONUtil;
import com.supermap.dataservice.util.Table;
import com.supermap.dubbo.api.temp.TempExpertNMService;
import com.supermap.dubbo.api.temp.TempUserNMService;
import com.supermap.dubbo.api.temp.entity.TempExpertNM;
import com.supermap.dubbo.api.temp.entity.TempUserNM;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Author:langhongshuai
 * @Description:临时内蒙专家表业务逻辑
 * @Date:18/8/10 上午10:58
 */
@Service
public class TempExpertNMServiceImpl implements TempExpertNMService{
    /**
     *使用指定类初始化日志对象，在日志输出的时候，可以打印出日志信息所在类
     */
    protected static final Logger logger = LoggerFactory.getLogger(TempExpertNMServiceImpl.class);

    @Autowired
    private TempExpertNMDao tempExpertNMDao;

    @Override
    public JSONUtil getExpertInfoByAreaname(String areaname,Table table) {
        //初始化Json封装工具类
        JSONUtil jsonUtil = new JSONUtil();
        try {
            List<TempExpertNM> tempExpertNMS = tempExpertNMDao.getExpertInfoByAreaname(areaname,table);

            //获取所有的专家后返回的json数据
            jsonUtil.setMsg("Get all tempnmexpert success！");
            jsonUtil.setIsSuccess(true);
            jsonUtil.setCode(200);
            jsonUtil.setData(tempExpertNMS);
        }catch (Exception e) {
            //捕捉数据库异常
            logger.error("TempExpertNMServiceImpl=>getExpertInfoByAreaname=>DaoException:"+e.getMessage());
            jsonUtil.setMsg("Get all tempnmexpert flase！");
            jsonUtil.setIsSuccess(false);
            jsonUtil.setCode(100);
        }
        return jsonUtil;
    }

    @Override
    public JSONUtil getExpertInfoCountByAreaname(String areaname) {
        //初始化Json封装工具类
        JSONUtil jsonUtil = new JSONUtil();
        try {
            List<TempExpertNM> tempUserNMS = tempExpertNMDao.getExpertInfoCountByAreaname(areaname);

            //获取所有的用户角色后返回的json数据
            jsonUtil.setMsg("Get all tempnmexpert count success！");
            jsonUtil.setIsSuccess(true);
            jsonUtil.setCode(200);
            jsonUtil.setData(tempUserNMS);
        }catch (Exception e) {
            //捕捉数据库异常
            logger.error("TempExpertNMServiceImpl=>getExpertInfoCountByAreaname=>DaoException:"+e.getMessage());
            jsonUtil.setMsg("Get all tempnmexpert count flase！");
            jsonUtil.setIsSuccess(false);
            jsonUtil.setCode(100);
        }
        return jsonUtil;
    }
}


